<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('作业-提交记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>作业题目：</label>
                                <input type="text" name="jobTitle"/>
                            </li>
                            <li>
                                <label>班级名称：</label>
                                <input type="text" name="className"/>
                            </li>
                            <li>
                                <label>学生名称：</label>
                                <input type="text" name="studentName"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status">
                                    <option value="">所有</option>
                                    <option value="1">已提交</option>
                                    <option value="2">已批阅</option>
                                    <option value="3">未提交</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:submit:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:submit:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />

    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:submit:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:submit:remove')}]];
        var prefix = ctx + "system/submit";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "作业-提交记录",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'className',
                    title: '班级名称'
                },
                {
                    field: 'studentName',
                    title: '学生名称'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        if(value === 1){
                            return '已提交'
                        }else if(value === 2){
                            return '已批阅'
                        }else if(value === 3){
                            return '未提交'
                        }
                    }

                },
                {
                    field: 'sumScore',
                    title: '所得分值'
                },
                    {
                        field: 'remark',
                        title: '作答内容'
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        console.log('roleName is', [[${roleName}]])
                        if((row.status == 3 || row.status == 1) && [[${roleName}]] == '学生'){
                            actions.push('<a class="btn btn-success btn-xs '  + '" href="javascript:void(0)" onclick="submit(\'' + row.id + '\')"><i class="fa fa-edit"></i>提交</a> ');
                        }
                        if(row.status == 1 && [[${roleName}]] == '教师'){
                            actions.push('<a class="btn btn-danger btn-xs '  + '" href="javascript:void(0)" onclick="piyue(\'' + row.id + '\')"><i class="fa fa-remove"></i>批阅</a>');
                        }
                        if(row.status == 2 && [[${roleName}]] == '教师'){
                            actions.push('<a class="btn btn-danger btn-xs '  + '" href="javascript:void(0)" onclick="view(\'' + row.id + '\')"><i class="fa fa-remove"></i>查看</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function submit(id) {
            $.modal.open('作业提交',prefix + '/submitJob/' + id,1500)
        }

        function piyue(id) {
            $.modal.open('作业批阅',prefix + '/piyue/' + id,1500)
        }

        function view(id) {
            $.modal.open('作业查看',prefix + '/viewJob/' + id,1500)
        }

        function dd(url) {
            console.log('url is',url)
            $.operate.get(ctx + 'common/download?fileName=' + url)
        }
    </script>
</body>
</html>
